<!DOCTYPE html>
<html>

<head lang="en">
	<meta charset="UTF-8">
	<title>注册</title>
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport"
		  content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
	<meta name="format-detection" content="telephone=no">
	<meta name="renderer" content="webkit">
	<meta http-equiv="Cache-Control" content="no-siteapp"/>

	<link rel="stylesheet" href="/static/home/AmazeUI-2.4.2/assets/css/amazeui.min.css"/>
	<link href="/static/home/css/dlstyle.css" rel="stylesheet" type="text/css">
	<script src="/static/home/AmazeUI-2.4.2/assets/js/jquery.min.js"></script>
	<script src="/static/home/AmazeUI-2.4.2/assets/js/amazeui.min.js"></script>

	<script>
		$(function () {

			window.onload = function () {
				//验证邮箱注册账号----------------------------------------------------------
				var emailFlag = false;

				var email = null;
				$('#email').blur(function () {
					email = $('#email').val();
					var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
					if (!reg.test(email)) {
						$('#emailTip').text('邮箱格式有误').css('color', 'red');
						emailFlag = false;
						return false;
					}
					//提交后台数据库验证
					email = $('#email').val();
					$.post('emailCheck', {email: email}, success, 'json');
				});

				//体验优化
				$('#email').focus(function () {
					if ($('#emailTip').text() == '邮箱格式有误' || $('#emailTip').text() == '邮箱已存在') {
						$('#emailTip').text('');
						emailFlag = false;
					} else if ($('#emailTip').text() == '邮箱可用') {
						$('#emailTip').text('');
						emailFlag = true;
					}
				});

				//我去1031 19:45终于开始密码了???*******************
				var pwdFlag = false;

				var password = null;
				$('#password').blur(function () {
					//验证密码位数
					password = $('#password').val();
					if (password.length < 6) {
						$('#pwdTip').text('密码少于6位').css('color', 'red');
						pwdFlag = false;
						return false;
					}
					//验证密码是否符合要求
					if (password == parseInt(password)) {
						$('#pwdTip').text('密码不能为纯数字').css('color', 'red');
						pwdFlag = false;
						return false;
					}
					$('#pwdTip').text('密码可用').css('color', 'blue');
					pwdFlag = true;
				});
				//密码输入体验优化
				$('#password').focus(function () {
					$('#pwdTip').text('');
				});

				//验证重复密码
				var repassword = null;
				$('#passwordRepeat').blur(function () {
					repassword = $('#passwordRepeat').val();
					if (password != repassword) {
						$('#repwdTip').text('两次密码不一致').css('color', 'red');
						pwdFlag = false;
					}
					pwdFlag = true;
				});
				//重复密码时体验优化
				$('#passwordRepeat').focus(function () {
					$('#repwdTip').text('');
				});

				//获取用户类型(普通用户\商家)****************
				var userType = null;
				$('#a').click(function () {
					userType = 1; //1代表普通用户
					if ($('#shop_name').length > 0) {
						$('#shop_name').remove();
					}
					if ($('#shop_nameTip').length > 0) {
						$('#shop_nameTip').remove();
					}
				});

				//判断用户名是否可用的标记物
				var shop_nameFlag = false;
				var userName = null;
				$('#b').click(function () {
					userType = 2;	//2代表商家

					//添加商家用户名***************************
					var oInput = document.createElement('input');
					oInput.id = 'shop_name';
					oInput.placeholder = '请输入商家名';

					if (!$('#shop_name').length > 0) {
						$('#radio').after(oInput);
					}

					var oDiv = document.createElement('div');
					oDiv.id = 'shop_nameTip';
					$('#shop_name').after(oDiv);

					$('#shop_name').blur(function () {
						userName = $('#shop_name').val();
						if (userName.length < 3) {
							$('#shop_nameTip').text('店铺名长度太短').css('color', 'red');
							shop_nameFlag = false;
							return false;
						}
						$.post('shopNameCheck', {username: userName}, success, 'json');
					});

				});

				//判断是否同意条款******************************
				var checkBox = null;
				$('#reader-me').bind('click', function () {
					if ($('#reader-me').is(':checked')) {
						checkBox = true;
					} else {
						checkBox = false;
					}
				});

				//提交注册信息************************
				$('#submit').click(function () {
					if (userType == 1) {
						if (emailFlag && pwdFlag && checkBox) {
							$.post('dataInsert', {
								email: email,
								password: password,
								userType: userType
							}, success, 'json');
						} else {
							alert('请检查输入信息');
						}
					} else if (userType == 2) {
						if (emailFlag && pwdFlag && checkBox && shop_nameFlag) {
							$.post('dataInsert', {
								email: email,
								password: password,
								userType: userType,
								username: userName
							}, success, 'json');
						} else {
							alert('请检查输入信息');
						}
					} else {
						alert('请检查输入信息');
					}
				});

				function success(obj) {
					switch (obj.state) {
						case 0:
							$('#emailTip').text('邮箱可用').css('color', 'blue');
							emailFlag = true;
							break;
						case 1:
							$('#emailTip').text('邮箱已存在').css('color', 'red');
							emailFlag = false;
							break;
						case 3:
							alert('注册成功');
							emailFlag = false;
							window.location.href = '/index/index/index';
							break;
						case 4:
							alert('商家注册成功');
							emailFlag = false;
							window.location.href = "/index/index/index";
							break;
						case 5:
							$('#shop_nameTip').text('用户名已存在').css('color', 'red');
							shop_nameFlag = false;
							break;
						case 6:
							$('#shop_nameTip').text('用户名可用').css('color', 'blue');
							shop_nameFlag = true;
							break;
						case 7:
							alert('注册失败, 请重试');
							break;
					}
				}
			};


			//手机号注册账号-----------------------------------------------------------------
			var phoneFlag = false;
			var phoneNumber = null;
			var oPhone = $('#phone');
			var oPhoneTip = $('#phoneTip');
			//号码可用标记位
			var reg = /^[1][3,4,5,7,8][0-9]{9}$/;
			oPhone.blur(function () {

				phoneNumber = oPhone.val();
				if ((phoneNumber.length == 11) && (parseInt(phoneNumber) == phoneNumber) && reg.test(phoneNumber)) {
					$.post('phoneCheck', {phone: phoneNumber}, phoneSuccess, 'json');

				} else {
					oPhoneTip.text('号码有误').css('color', 'red');
					phoneFlag = false;
					codeTip.text('');
					clearInterval(timer);
					sendNum = 0;
					return false;
				}
			});


			//好了验证短信验证码------------------------------------
			var oBtn = $('#sendMobileCode');
			var codeTip = $('#codeTip');
			var codeFlag = false;		//验证码标记位, true表示验证码输入正确, false表示错误

			oBtn.mousedown(function (evt) {

				setTimeout(function () {
					if (phoneFlag) {
						$.post('phoneCode', {phone: phoneNumber}, phoneSuccess, 'json');
					}
				}, 600);

			});
			//验证验证码是否正确
			var responseCode = null;		//ajax后台响应返回的验证码
			var codeInput = $('#code');		//验证码提示对象
			codeInput.blur(function () {
				if ($.trim(codeInput.val()) == responseCode) {
					codeTip.text('验证码正确').css('color', 'blue');
					codeFlag = true;
					if (timer) {
						clearInterval(timer);
						sendNum = 0;
					}
				} else {
					codeTip.text('验证码有误, 请重新输入').css('color', 'red');
					clearInterval(timer);
					sendNum = 0;
					codeFlag = false;
				}
			});

			//验证密码--------------------------------------------------
			var pwdFlag = false; 	//密码是否符合要求标记, 符合ture, 否则false;

			var oPwd = $('#telpassword');		//密码对象
			var oPwdVal = oPwd.val();
			var oPwdRpt = $('#telpasswordRepeat');		//重复密码对象
			var opwdTip = $('#telpwdTip');		//密码提示对象
			var opwdRptTip = $('#telpwdrepTip');		//重复密码提示对象
			oPwd.blur(function () {
				if ($.trim(oPwd.val()).length < 6) {
					opwdTip.text('密码不能小于6位').css('color', 'red');
					pwdFlag = false;
					return false;
				}

				if (parseInt(oPwd.val()) == oPwd.val()) {
					opwdTip.text('密码不能位纯数字').css('color', 'red');
					pwdFlag = false;
					return false;
				}
				opwdTip.text('密码可用').css('color', 'blue');
			});
			oPwdRpt.blur(function () {
				if (oPwdRpt.val() != oPwd.val()) {
					opwdRptTip.text('两次密码不一致').css('color', 'red');
					pwdFlag = false;
					return false;
				}
				opwdRptTip.text('');
				pwdFlag = true;
			});

			//商家还是个人用户---------------------------------------------
			var userFlag = null;		//电话注册用户标记, 1表示个人用户, 2表示商家

			var Operson = $('#tel_a');	//个人用户对象
			var Oshoper = $('#tel_bb');	//商家用户对象
			Operson.click(function () {
				userFlag = 1;
				if (Oinput) {
					Oinput.css('display', 'none').val('');
					Ospan.css('display', 'none').text('');
				}
			});
			var Oinput = $('#telnameInput');		//店铺名输入框对象
			var Ospan = $('#tel_nameTip');		//店铺名提示信息

			//验证商家用户名是否符合要求*************************
			var shopnameFlag = false;  //商家用户名标记位, true表示用户名合法

			var telshopName = null;
			Oshoper.click(function () {
				userFlag = 2;
				Oinput.css('display', 'inline');
				Ospan.css('display', 'inline')
			});

			Oinput.blur(function () {
				telshopName = $.trim(Oinput.val());
				if (telshopName.length < 3) {
					Ospan.text('商铺名太短').css('color', 'red');
					shopnameFlag = false;
					return false;
				} else {
					$.post('userNameCheck', {username: telshopName}, phoneSuccess, 'json');
				}
			});

			//是否同意条约**************************
			var noticeFlag = false; 	//是否同意条款, 同意true

			$('#telnotice').click(function () {
				if ($('#reader-meR').is(':checked')) {
					noticeFlag = true;
				} else {
					noticeFlag = false;
				}
			});

			//根据用户类型插入数据库
			$('#telsubmit').click(function () {
				setTimeout(function () {
					if (userFlag == 1) {
						if (phoneFlag && codeFlag && pwdFlag && noticeFlag) {
							$.post('teldataInsert', {
								phone: phoneNumber,
								pwd: oPwdVal,
								useType: 1
							}, phoneSuccess, 'json');
							return false;
						}
					} else if (userFlag == 2) {
						if (phoneFlag && codeFlag && pwdFlag && noticeFlag && shopnameFlag) {
							$.post('teldataInsert', {
								phone: phoneNumber,
								pwd: oPwd.val(),
								shopname: telshopName,
								useType: 2
							}, phoneSuccess, 'json');
							return false;
						}
					}
					alert('请检查信息');

				}, 500);
			});

			var sendNum = 0;	// 0 表示点击允许发送短信, 1表示不允许
			var timer = null;		//计时器变量
			function phoneSuccess(data) {
				switch (data.state) {
					case 1:
						if (sendNum == 0) {
							codeTip.text('已发送, 请于1分钟后重新发送').css('color', 'red');
							var i = 60;
							sendNum = 1;
							timer = setInterval(function () {
								i--;
								codeTip.text('已发送, 请于' + i + '秒后重新重试');
								if (i == 0) {
									clearInterval(timer);
									sendNum = 0;
									codeTip.text('请重新发送').css('color', 'blue');
								}
							}, 1000);
						}
						break;
					case 2:
						clearInterval(timer);
						sendNum = 0;
						codeTip.text('验证码已发送').css('color', 'blue');
						responseCode = data.num;
						console.log(responseCode);

						break;
					case 3:
						oPhoneTip.text('此号码已注册').css('color', 'red');
						codeTip.text('');
						phoneFlag = false;
						break;
					case 4:
						oPhoneTip.text('号码可用').css('color', 'blue');
						phoneFlag = true;
						break;
					case 5:
						Ospan.text('店铺名已存在').css('color', 'red');
						shopnameFlag = false;
						break;
					case 6:
						Ospan.text('店铺名可用').css('color', 'blue');
						shopnameFlag = true;
						break;
					case 7:
						alert('用户注册成功');
						phoneFlag = false;
						window.location.href = '/index/index/index';
						break;
					case 8:
						alert('注册失败请重试');
						phoneFlag = true;
						break;
					case 9:
						alert('店小二注册成功');
						phoneFlag = false;
						window.location.href = '/index/index/index';
						break;
				}
			}


		});

	</script>
</head>

<body>

<div class="login-boxtitle">
	<a href="/index/index/index"><img alt="" src="/static/home/images/logobig.png"/></a>
</div>

<div class="res-banner">
	<div class="res-main">
		<div class="login-banner-bg"><span></span><img src="/static/home/images/big.jpg"/></div>
		<div class="login-box">

			<div class="am-tabs" id="doc-my-tabs">
				<ul class="am-tabs-nav am-nav am-nav-tabs am-nav-justify">
					<li class="am-active"><a href="">邮箱注册</a></li>
					<li><a href="">手机号注册</a></li>
				</ul>

				<div class="am-tabs-bd">
					<div class="am-tab-panel am-active">
						<form>

							<div class="user-email">
								<label for="email"><i class="am-icon-envelope-o"></i></label>
								<input type="email" name="" id="email" placeholder="请输入邮箱账号" value="">
							</div>
							<div>
								<span id="emailTip"></span>
							</div>
							<div class="user-pass">
								<label for="password"><i class="am-icon-lock"></i></label>
								<input type="password" name="" id="password" placeholder="设置密码">
							</div>
							<div>
								<span id="pwdTip"></span>
							</div>
							<div class="user-pass">
								<label for="passwordRepeat"><i class="am-icon-lock"></i></label>
								<input type="password" name="" id="passwordRepeat" placeholder="确认密码">
							</div>
							<div>
								<span id="repwdTip"></span>
							</div>

						</form>

						<div style="font-size: 14px; margin-top: -15px; height: 10px;"
							 class="login-links" id="radio">
								<span style="float: left; ">
									<label for="a" style="float: left; ">
										<input type="radio" style="width: 10px; height: 10px;"
											   id="a" name="radio">普通用户
									</label>
								</span>
							<span style="float: left; margin-left: 10px">
									<label for="b" style="float: left; ">
										<input type="radio" style="width: 10px; height: 10px"
											   id="b" name="radio">商家
									</label>
								</span>
						</div>
						<div class="login-links" style="margin-top: 10px">
							<label for="reader-me">
								<input id="reader-me" type="checkbox"> 点击表示您同意商城《服务协议》
							</label>
						</div>
						<div class="am-cf">
							<input type="submit" name="" value="注册" class="am-btn am-btn-primary am-btn-sm am-fl"
								   id="submit">
						</div>
					</div>


					<div class="am-tab-panel">
						<form>
							<div class="user-phone">
								<label for="phone"><i class="am-icon-mobile-phone am-icon-md"></i></label>
								<input type="tel" name="" id="phone" placeholder="请输入手机号">
							</div>
							<div>
								<span id="phoneTip"></span>
							</div>

							<div class="verification">
								<label for="code"><i class="am-icon-code-fork"></i></label>
								<input type="tel" name="" id="code" placeholder="请输入验证码">
								<a class="btn" href="#"
								   id="sendMobileCode">
									<span id="dyMobileButton">获取</span></a>
							</div>
							<div>
								<span id="codeTip"></span>
							</div>

							<div class="user-pass">
								<label for="password"><i class="am-icon-lock"></i></label>
								<input type="password" name="" id="telpassword" placeholder="设置密码">
							</div>
							<div>
								<span id="telpwdTip"></span>
							</div>
							<div class="user-pass">
								<label for="passwordRepeat"><i class="am-icon-lock"></i></label>
								<input type="password" name="" id="telpasswordRepeat" placeholder="确认密码">
							</div>
							<div>
								<span id="telpwdrepTip"></span>
							</div>
						</form>


						<div style="font-size: 14px; margin-top: -15px; height: 10px;"
							 class="login-links" id="tel_radio">
								<span style="float: left; ">
									<label for="tel_a" style="float: left; ">
										<input type="radio" style="width: 10px; height: 10px;"
											   id="tel_a" name="radio">普通用户
									</label>
								</span>
							<span style="float: left; margin-left: 10px" id="tel_bb">
									<label for="tel_b" style="float: left; ">
										<input type="radio" style="width: 10px; height: 10px"
											   id="tel_b" name="radio">商家
									</label>
								</span>
						</div>

						<div>
							<input id="telnameInput" placeholder="请输入商铺名" style="display: none;">
							<span id="tel_nameTip"></span>
						</div>

						<div class="login-links" style="margin-top: 10px" id="telnotice">
							<label for="reader-meR">
								<input id="reader-meR" type="checkbox" style="margin-top: 2px"> 点击表示您同意商城《服务协议》
							</label>
						</div>
						<div class="am-cf" id="telsubmit">
							<input type="submit" name="" value="注册" class="am-btn am-btn-primary am-btn-sm am-fl">
						</div>

						<hr>
					</div>

					<script>
						$(function () {
							$('#doc-my-tabs').tabs();
						})
					</script>

				</div>
			</div>

		</div>
	</div>

	<div class="footer ">
		<div class="footer-hd ">
			<p>
				<a href="# ">创科科技</a>
				<b>|</b>
				<a href="/index/index/index">商城首页</a>
				<b>|</b>
				<a href="# ">支付宝</a>
				<b>|</b>
				<a href="# ">物流</a>
			</p>
		</div>
		<div class="footer-bd ">
			<p>
				<a href="# ">关于创科</a>
				<a href="# ">合作伙伴</a>
				<a href="# ">联系我们</a>
				<a href="# ">网站地图</a>
				<em>© 2015-2025 Hengwang.com 版权所有</em>
			</p>
		</div>
	</div>
</div>
</body>

</html>